<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
        body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
    </style>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=v1ynHS570GgGL2HinECWssLGx6U1AOIE"></script>
    <title>浏览器定位</title>
</head>
<body>
<div id="demo"></div>
</body>
</html>
<script>
    function getLocation(){
        if (navigator.geolocation){
            navigator.geolocation.getCurrentPosition(showPosition);
        }else{
            alert("出错啦")
        }
    }
    var geoc = new BMap.Geocoder();
    function showPosition(position){
        var point = new BMap.Point(position.coords.longitude,position.coords.latitude);
        geoc.getLocation(point, function(rs){
            var addComp = rs.addressComponents;
            alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
        });
    }
    getLocation();
</script>
